package com.xxgc.helloworld.util;

import com.xxgc.helloworld.job.SendMsgJob;
import com.xxgc.helloworld.scheduler.QuartzScheduler;
import com.xxgc.helloworld.utils.QuartzManagerUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Timer;
import java.util.TimerTask;

/**
 * @program: helloword
 * @description: 定时任务测试
 * @author: liutao
 * @create: 2022-03-08 18:50
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class TimerDemo {
    @Autowired
    QuartzScheduler quartzScheduler;

    @Test
    public void test() throws InterruptedException {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("女神，你在吗？");
            }
        },1000,5000);//延迟1s后每隔5秒执行一次
        Thread.sleep(500000);
    }
    @Test
    public void test1() throws SchedulerException, InterruptedException {
        /*  2022年 3月 8日 20时 20分 0秒开始 每5秒执行一次  */
        QuartzManagerUtils.addJob("打工仔", SendMsgJob.class,"0/3 * * * * ? *");
        Thread.sleep(500000);
    }
}